from django.shortcuts import render

# Create your views here.
from rest_framework import generics
from rest_framework import permissions
from .models import Product
from rest_framework.views import APIView
from rest_framework.response import Response
from axf.util.JSONHttpResponse import JSONHttpResponse
from .serializers import ProductListSerializer
from rest_framework.exceptions import NotFound
import json
import datetime
import logging
LOG_FILENAME = 'shop.log'

#logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG)
logging.basicConfig(filename=LOG_FILENAME,level=logging.INFO)

class ProductListView(APIView):
    """
    产品列表
    """
    def get(self,request,format=None):
    	queryset = Product.objects.all()
    	print(len(queryset))
    	serializer = ProductListSerializer(queryset,many=True)
    	logging.info('%s',serializer.data)
    	# serializerData = {
    	# 	'errcode': 0,
    	# 	'data': serializer
    	# }
    	resp = {"errcode":0,"msg":"success"}
    	resp['data'] = serializer.data
    	return JSONHttpResponse(resp)
    
